package hotgammon.domain;

public class StrategyMoveDeltamon implements StrategyMove{

	public boolean move(Board board, Game game, Location from, Location to, Boolean validate) {
		//Can't move if it is not your turn
		if(!game.getColor(from).equals(game.getPlayerInTurn())){
			return false;
		}
		//No checker can be moved to a place with another color
		else if(game.getCount(to)>=0 && !game.getColor(from).equals(game.getColor(to)) && !game.getColor(to).equals(Color.NONE) ){
			return false;
		}
		//Correct direction movement
		else if(game.getColor(from).equals(Color.BLACK) && Location.distance(from, to)<0){
			return false;
		}else if(game.getColor(from).equals(Color.RED) && Location.distance(from, to)>0){
			return false;
		}

		//can only move the values the dices show
		else if(!diceValuesContains(game.diceValuesLeft(),Math.abs(Location.distance(from, to)))){
			return false;
		}

		
		//Legal move
		if(!validate)board.move(from, to);
		return true;
	}
	
	
	private boolean diceValuesContains(int[] values, int distance){
		for(int i = 0; i < values.length ; i++){
			if(values[i] == distance) return true;
		}
		return false;
	}

}
